#pragma once
#include <osgViewer/Viewer>
#include "OGroup.h"

class Scene {
public:
	static void init();
	
	static void add(Entity* entity, bool RTT = false) {/**@brief RTT: Render To Texture */
		if (!entity) return;
		if (!RTT)
			s_root->addEntity(entity);
		else {
			if (!s_root->hasSubgraphCamera())
				s_root->createSubgraphCamera(s_viewer->getCamera());
			s_root->addToSubgraphCamera(entity);
		}
	}

	static void remove(Entity* entity, bool RTT = false) {
		if (!entity) return;
		if (!RTT)
			s_root->removeEntity(entity);
		else
			s_root->removeFromSubgraphCamera(entity);
	}

	static CVector<Entity*> entities() { return s_root->entities(); }

	static void destroySubgraphCamera() { s_root->destroySubgraphCamera(); }

	static void run();

	static void clear();

	static void destroy() { s_viewer = nullptr; }// empty ref_ptr

private:
	Scene() = default;

	static bool isActive() { return s_viewer && !s_viewer->done(); }

	static void debugKeyEvents();

	static osg::ref_ptr<osgViewer::Viewer> s_viewer;
	static OGroup* s_root;
};